/*

Author   : chaos

FileName : tmp_link_list.cpp

Date     : 15/08/17 22:06:30

*/
#include <iostream>
using namespace std;

template <class TYPE> class ListNode
{
    private:
        TYPE data;
        ListNode * next_node;
        static ListNode * now;
        const static ListNode * head;

    public:
        ListNode(TYPE node_data):data(node_data),next_node(NULL){}
        ListNode():next_node(NULL){head = now = this;}
        static void add_node(TYPE new_data);

        static void show_all_node();
};

template <class TYPE> ListNode<TYPE> * ListNode<TYPE>::now;

template <class TYPE> const ListNode<TYPE> * ListNode<TYPE>::head;

template <class TYPE> void ListNode<TYPE>::add_node(TYPE new_data)
{
    now->next_node = new ListNode(new_data);
    now = now->next_node;
}

template <class TYPE> void ListNode<TYPE>::show_all_node()
{
    int i = 0;
    now = head->next_node;

    while(now != NULL)
    {
        i++;
        cout << "The data of " << i << "node is "
            << now->data << "." << endl;

        now = now->next_node;
    }
}

int main(int argc ,char *argv[])
{
    ListNode<int> i_head;

    ListNode<double> f_head;

    for( int i = 1; i < 4 ; i++ )
    {
        i_head.add_node(i);
        f_head.add_node(i*0.1);
    }

    ListNode<int>::show_all_node();
    ListNode<double>::show_all_node();
    return 0;
}
